﻿using System.Collections.Generic;
using System.Linq;
using Sps.Abrs.Model;

namespace ABRS.WEB.Services.Rest
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码、svc 和配置文件中的类名“LayerInfoService”。
    public class LayerService : ILayerService
    {
        readonly Sps.Abrs.BLL.Layerinfo _layerinfoBll = new Sps.Abrs.BLL.Layerinfo();
        private readonly Sps.Abrs.BLL.LayerField _layerFieldBll = new Sps.Abrs.BLL.LayerField();
        public List<LayerWithField> GetLayerInfos()
        {
            var fields = _layerFieldBll.GetModelList("");
            var layers =_layerinfoBll.GetModelList("");
            var layerWiheFields = new List<LayerWithField>();
            foreach (var layer in layers)
            {
                if (!layer.queryable) continue;
                var layerWithField = new LayerWithField();
                layerWithField.name = layer.name;
                layerWithField.caption = layer.caption;
                layerWithField.fields = fields.Where(field => field.layerId == layer.id).ToList();
                layerWiheFields.Add(layerWithField);
            }
            return layerWiheFields;
        }



        public List<LayerField> GetLayerFieldsInfos()
        {
            return _layerFieldBll.GetModelList("");
        }
    }
}
